package sii.dati;

import sii.commons.Log;
import sii.dati.DataManagerException;
import sii.dati.Datasource;


public abstract class DataManagerDB {
   protected Datasource datasource;
   private Log log;

    protected DataManagerDB() throws DataManagerException {
	try {
	    datasource = Datasource.getInstance();
	    log = new Log(DataManagerDB.class);
	    
	} catch (Exception e) {
	    String msg = "Errore durante la creazione di DataManagerDB: " + e.getMessage();
	    log.error(msg,e);
	    throw new DataManagerException(msg);
	} 
    }

    protected void execute(String sql) throws DataManagerException{
	try {
	    datasource.getConnection().prepareStatement(sql).execute();
	} catch (Exception e) {
	    String msg = "Errore durante la creazione di DataManagerDB: " + e.getMessage();
	    log.error(msg,e);
	    throw new DataManagerException(msg);
	}
    }
    protected void close(){
	datasource = null;
    }

}
